import org.junit.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

public class Homework {
    static Semaphore sp = new Semaphore(3);

    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(Integer.MAX_VALUE / 100);

        for(int i = 0; i < 20; i++){
            service.submit( new User("车主"+i,sp));
        }

        service.shutdown();
    }
}

class User extends Thread{
    private String name = null;
    private Semaphore sp = null;

    public User(String name, Semaphore sp) {
        this.name = name;
        this.sp = sp;
    }

    @Override
    public void run() {
        try {
            sp.acquire();
            System.out.println(name+"开车进入了车库------");
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            System.out.println(name+"开车驶出了车库......");
            sp.release();
        }
    }
}